home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
makmenu2.zip
/
MAKMENU2.BAS
next >
Wrap
BASIC Source File
|
1989-08-09
|
8KB
|
257 lines
FUNCTION MakMenu2% (choozit$(), NumofChoices%, LeftColumn%, Row%, fg%, bg%, fgl%, hfg%, hbg%)
REDIM firstletter$(NumofChoices%), spot%(NumofChoices%), temp$(NumofChoices%)
'=== Set local variables - extended scan codes for keypad keys
piknumber = 0
Up$ = CHR$(0) + CHR$(72)
Down$ = CHR$(0) + CHR$(80)
Enter$ = CHR$(13)
Home$ = CHR$(0) + CHR$(71)
End$ = CHR$(0) + CHR$(79)
PgUp$ = CHR$(0) + CHR$(73)
PgDn$ = CHR$(0) + CHR$(81)
esc$ = CHR$(0) + CHR$(27)
'=== Check for out-of-bounds parameters. If any are out of range, quit the function
IF NumofChoices% < 2 OR NumofChoices% > 23 THEN EXIT FUNCTION
IF LeftColumn% < 1 OR LeftColumn% > 80 THEN EXIT FUNCTION
IF Row% < 1 OR Row% > 23 OR (Row% + NumofChoices%) > 24 THEN EXIT FUNCTION
'=== Calculate length of longest menu choice and store value in ChoiceLen%
choicelen% = 0
FOR x% = 1 TO NumofChoices%
IF LEN(choozit$(x%)) > choicelen% THEN
choicelen% = LEN(choozit$(x%))
END IF
NEXT x%
'=== Check to make sure longest menu choice will fit on screen
IF (LeftColumn% + choicelen%) > 80 THEN EXIT FUNCTION
'=== Put first character of each choice in firstletter$()
FOR x% = 1 TO NumofChoices%
firstletter$(x%) = UCASE$(LEFT$(choozit$(x%), 1))
spot%(x%) = x%
NEXT x%
'=== Sort the firstletter$ array
CALL QwikSort(firstletter$(), spot%(), NumofChoices%)
'=== Move firstletter$() into array with variables in ascending alpha order
FOR I = 1 TO NumofChoices%
temp$(I) = firstletter$(spot%(I))
NEXT I
'=== Set flag if number of choices<=10. Then add integers to menu if set.
IF NumofChoices% <= 10 THEN
piknumber = 1
choicelen% = choicelen% + 4
IF (LeftColumn% + choicelen%) > 80 THEN EXIT FUNCTION
END IF
SELECT CASE NumofChoices%
CASE 0 TO 9
min$ = CHR$(49)
CASE 10
min$ = CHR$(48)
CASE IS > 10
min$ = ""
max$ = ""
END SELECT
IF NumofChoices% <= 10 THEN max$ = CHR$(48 + NumofChoices%)
'=== Print menu choices to screen
FOR x% = 1 TO NumofChoices%
LOCATE (Row% - 1) + x%, LeftColumn%
COLOR fgl%, bg%
IF piknumber THEN
seq = x%
IF x% = 10 THEN seq = 0
PRINT RIGHT$(STR$(seq), 1); " - "; LEFT$(choozit$(x%), 1);
COLOR fg%, bg%
PRINT RIGHT$(choozit$(x%), LEN(choozit$(x%)) - 1)
ELSE
PRINT LEFT$(choozit$(x%), 1);
COLOR fg%, bg%
PRINT RIGHT$(choozit$(x%), LEN(choozit$(x%)) - 1)
END IF
NEXT x%
'=== Highlight the first entry in the list.
currentlocation% = 1
COLOR hfg%, hbg%
LOCATE (Row% - 1) + currentlocation%, LeftColumn%
PRINT SPACE$(choicelen%)
LOCATE (Row% - 1) + currentlocation%, LeftColumn%
IF piknumber THEN PRINT "1 - ";
PRINT choozit$(currentlocation%)
'=== Read keystrokes and change the highlighted entry appropriately
ExitCode = false
WHILE ExitCode = false
'=== Read keystrokes
key$ = ""
WHILE key$ = ""
LET key$ = UCASE$(INKEY$)
WEND
SELECT CASE key$
'=== Legal movement
CASE Up$, Down$, Home$, End$, PgUp$, PgDn$, min$ TO max$, temp$(1) TO temp$(NumofChoices%)
'=== Restore old highlighted choice to normal colors
LOCATE (Row% - 1) + currentlocation%, LeftColumn%
COLOR fg%, bg%: PRINT SPACE$(choicelen%)
COLOR fgl%, bg%
LOCATE (Row% - 1) + currentlocation%, LeftColumn%
IF piknumber THEN
PRINT RIGHT$(STR$(currentlocation%), 1); " - "; LEFT$(choozit$(currentlocation%), 1);
COLOR fg%, bg%
PRINT RIGHT$(choozit$(currentlocation%), LEN(choozit$(currentlocation%)) - 1)
ELSE
PRINT LEFT$(choozit$(currentlocation%), 1);
COLOR fg%, bg%
PRINT RIGHT$(choozit$(currentlocation%), LEN(choozit$(currentlocation%)) - 1)
END IF
CASE ELSE
'Nothing
END SELECT
'=== Update the highlight bar's location based on which key was hit
SELECT CASE key$
CASE Up$
'=== Set new CurrentLocation%
IF currentlocation% = 1 THEN
currentlocation% = NumofChoices%
ELSE
currentlocation% = currentlocation% - 1
END IF
CASE Down$
'=== Set New CurrentLocation%
IF currentlocation% = NumofChoices% THEN
currentlocation% = 1
ELSE
currentlocation% = currentlocation% + 1
END IF
CASE Enter$
'=== Set makmenu2 to highlighted selection and exit ===
MakMenu2% = currentlocation%
'=== Instead of using ExitCode to beak out of this, we have to use
'=== EXIT FUNCTION, or it never quits.
EXIT FUNCTION
CASE Home$, PgUp$
'=== Set New CurrentLocation%
currentlocation% = 1
CASE End$, PgDn$
'=== Set New CurrentLocation%
currentlocation% = NumofChoices%
CASE min$ TO max$
IF piknumber THEN
IF NumofChoices% = 10 AND VAL(key$) = 0 THEN
currentlocation% = NumofChoices%
ELSE
currentlocation% = VAL(key$)
END IF
END IF
CASE temp$(1) TO temp$(NumofChoices%)
oldspot% = currentlocation%
FOR x% = 1 TO NumofChoices%
IF temp$(x%) = key$ THEN
currentlocation% = spot%(x%)
GOTO done
END IF
NEXT x%
IF currentlocation% = oldspot% THEN BEEP
CASE ELSE
'Illegal key - leave everything as is
BEEP
done:
END SELECT
'=== Highlight the entry indicated by CurrentLocation%
SELECT CASE key$
CASE Up$, Down$, Home$, End$, PgUp$, PgDn$, min$ TO max$, temp$(1) TO temp$(NumofChoices%)
'=== Highlight new choice
COLOR hfg%, hbg%
LOCATE (Row% - 1) + currentlocation%, LeftColumn%
IF piknumber THEN
PRINT RIGHT$(STR$(currentlocation%), 1); " - "; choozit$(currentlocation%)
ELSE
PRINT choozit$(currentlocation%)
END IF
CASE ELSE
'Nothing
END